// pages/tuibao-integral-mall/hotGoods/hotGoods.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data: [
      {
        title: '来一贴来一贴来一贴来一贴来一贴来一贴来一贴来一贴来一贴来一贴来一贴来一贴',
        price: 388,
        zan: 388,
        url: '/images/1.png'
      },
      {
        title: '来一贴',
        price: 388,
        zan: 388,
        img: '/images/1.png'
      },
    ],
    page: 1,
    goods_list: []
  },
  goodsInfo: function (e) {
    let that = this;
    var r = this.data.integral, s = e.currentTarget.dataset.integral;
    let goods_index = e.currentTarget.dataset.index
    if (parseInt(r) < parseInt(s)) return getApp().core.showToast({
      title: "爱心不足!",
      image: "/images/icon-warning.png"
    })
    console.log(that.data.goods_list, goods_index)
    let a = JSON.parse(that.data.goods_list[goods_index].attr)[0].attr_list[0]
    let attr = [{
      attr_group_id: 0,
      attr_group_name: '规格',
      attr_id: a.attr_id,
      attr_name: a.attr_name
    }]
    let goods_id = e.currentTarget.dataset.goodsId;
    let attr_price
    let attr_integral
    let type = e.currentTarget.dataset.type
    getApp().core.navigateTo({
      url: "/pages/integral-mall/goods-info/index?goods_id=" + goods_id + "&integral=" + this.data.integral
    });

  },
  getList(){
    getApp().request({
      url: getApp().api.integral.integralmall_goods_list,
      data: {
        is_hot: 1,
        page: this.data.page
      },
      success: (res)=> {
        if(res.code == 0){
          let page = this.data.page
          if (res.data.list.length > 0) {
            page ++
            this.setData({
              goods_list: this.data.goods_list.concat(res.data.list),
              page
            })
          }
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})